home *** CD-ROM | disk | FTP | other *** search
/ Night Owl - The Best of BBS / Night Owl The Best of BBS (NOP-BBS) (Night Owl Publisher) (1994).iso / 014a / ezbbs215.lha / Source / eazy2mail.c < prev    next >
C/C++ Source or Header  |  1994-02-07  |  3KB  |  143 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <fcntl.h>
  5. #include <time.h>
  6. #include <proto/dos.h>
  7. #include <proto/exec.h>
  8.  
  9.  
  10.  
  11. #define VERSION "1.8"
  12. static char *version = "\0$VER: eazy2mail "VERSION" ("__AMIGADATE__")";
  13.  
  14.  
  15.  
  16. #define MAIL_BATCHSCRIPT    "MB_DATA:UUCP/DeliverMails.scp"
  17. #define MAIL_BATCHLOCK        "MB_DATA:UUCP/DeliverMails.lock"
  18. #define MAIL_BATCHNUM        "MB_DATA:UUCP/DeliverMails.num"
  19. #define MAIL_BATCHFILE        "MB_DATA:UUCP/Mail.%ld"
  20.  
  21.  
  22.  
  23. void space2under(char *s)
  24. {
  25.   while (s && *s) {
  26.     if (*s==' ')
  27.       *s = '_';
  28.     s++;
  29.   }
  30. }
  31.  
  32.  
  33.  
  34. int main(int argc, char *argv[])
  35. {
  36.   if (argc==6) {
  37.     char tmp[80];
  38.     FILE *fp,*scp,*lock,*num;
  39.     long mailnum = 0;
  40.  
  41.     /* try to get lock */
  42.  
  43.     while (!(lock=fopen(MAIL_BATCHLOCK,"w")))
  44.       Delay(100);
  45.  
  46.     /* we have the lock, now want the maximum mail-number */
  47.  
  48.     if (num=fopen(MAIL_BATCHNUM,"r")) {
  49.       fscanf(num,"%ld",&mailnum);
  50.       fclose(num);
  51.     }
  52.  
  53.     ++mailnum;
  54.  
  55.     sprintf(tmp,MAIL_BATCHFILE,mailnum);
  56.  
  57.     if (mailnum>1) {
  58.       while (!(scp=fopen(MAIL_BATCHSCRIPT,"a"))) {
  59.         Delay(100);
  60.       }
  61.     }
  62.     else {
  63.       while (!(scp=fopen(MAIL_BATCHSCRIPT,"w"))) {
  64.         Delay(100);
  65.       }
  66.       fprintf(scp,"delete %s\n",MAIL_BATCHNUM);
  67.     }
  68.  
  69.     /* write back new mail-number while script-file is locked by us */
  70.     if (num=fopen(MAIL_BATCHNUM,"w")) {
  71.       fprintf(num,"%ld\n",mailnum);
  72.       fclose(num);
  73.     }
  74.  
  75.     /* now finish writing to script-file */
  76.     fprintf(scp,"sendmail <%s\ndelete %s\n",tmp,tmp);
  77.  
  78.     if (fp=fopen(tmp,"w")) {
  79.       register int c=0,last=0;
  80.       time_t t;
  81.       struct tm *ut;
  82.       char uname[16];
  83.       char *sname = argv[2];
  84.       char *tonam = argv[4];
  85.       char *realn = argv[3];
  86.       char *sbjct = argv[5];
  87.  
  88.       time(&t);
  89.       ut = gmtime(&t);
  90.  
  91.       strcpy(uname,argv[1]);
  92.       space2under(uname);
  93.  
  94.       fprintf(fp,"From: %s@%s (%s)\n",uname,sname,realn);
  95.       fprintf(fp,"To: %s\n",tonam);
  96.       fprintf(fp,"Sender: eazybbs@%s\n",sname);
  97.       fprintf(fp,"Subject: %s\n",sbjct);
  98.       fprintf(fp,"MIME-Version: 1.0\n");
  99.       fprintf(fp,"Content-Type: text/plain; charset=ISO-8859-1\n");
  100.       fprintf(fp,"Content-Transfer-Encoding: 8bit\n");
  101.       fprintf(fp,"\n");
  102.  
  103.       while ((c=getchar())!=EOF) {
  104.         if (last=='\\') {
  105.           switch (c) {
  106.           case '\\': fputc(c,fp);
  107.                      break;
  108.           default  : break;
  109.           }
  110.           last = 0;
  111.         }
  112.         else if (c=='\\') {
  113.           last = c;
  114.         }
  115.         else {
  116.           fputc(c,fp);
  117.           last = c;
  118.         }
  119.       }
  120.       fprintf(fp,"\n");
  121.  
  122.       fclose(fp);
  123.     }
  124.  
  125.     /* close script-file here to prevent it from being started */
  126.     fclose(scp);
  127.  
  128.     while (chmod(MAIL_BATCHSCRIPT,S_IWRITE|S_IREAD|S_IEXECUTE|S_IDELETE|S_ISCRIPT))
  129.       Delay(100);
  130.  
  131.     /* close lock-file here to prevent other ports from processing mails */
  132.     fclose(lock);
  133.  
  134.   }
  135.   else {
  136.     fprintf(stderr,"\033[1;33mEazyBBS\033[0m ⌐ 1988-1994 Andreas M. Kirchwitz\n"
  137.                    "Usage: eazy2mail \033[3m<user> <site> <real> <to> <subject> \033[0m <text\n");
  138.   }
  139.  
  140.   exit(0);
  141. }
  142.  
  143.